package com.link2room.optimus.nmsrunner;

import com.aliyun.mns.model.Message;
import com.link2room.common.enums.BaseSysExceptionEnum;
import com.link2room.common.util.*;
import com.link2room.optimus.dto.param.manager.RateplanHotelManagerParamDto;
import com.link2room.common.mns.Worker;
import com.link2room.optimus.facade.IMarketingFacadeService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * Created by sss on 2016/9/21.
 */
@Component("l2RRateplanHotelRunner")
public class L2RRateplanHotelRunnerImpl implements Worker {
    @Resource
    private IMarketingFacadeService marketingFacadeService;

    @Override
    public boolean exec(Message message) throws Exception {
        try{
            RateplanHotelManagerParamDto rateplanHotelManagerParamDto = JacksonUtil.jsonToBean(message.getMessageBody(), RateplanHotelManagerParamDto.class);
            if(message.getDequeueCount()==1){
                marketingFacadeService.saveOrUpdateRateplanHotel(rateplanHotelManagerParamDto);
            }else {
                BatchUtil.doBatchTaskFail(rateplanHotelManagerParamDto.getTaskMainId(),rateplanHotelManagerParamDto.getTaskId(), BaseSysExceptionEnum.MNS_COUNT_ABOVE.getMsg());
            }
            return true;
        }catch (Exception e){
            String errorDetail= ExceptionUtil.getExceptionDetail(e);
            LogUtil.logger.error(errorDetail);
            return false;
        }
    }
}
